package cn.kgc.demo.config;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.DefaultPropertySourceFactory;
import org.springframework.core.io.support.EncodedResource;

import java.io.IOException;
import java.util.Properties;

public class YmlPropertySourceFactory extends DefaultPropertySourceFactory {


    @Override
    public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
        return super.createPropertySource(name, resource);
    }

    public Properties YmlPropertySourceFactory(EncodedResource resource) {
        YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean();
        ypfb.setResources(resource.getResource());
        ypfb.afterPropertiesSet();
        return ypfb.getObject();
    }


}
